#!/bin/bash
# Este script verifica se o backup foi executado de uma lista de servidores
# by wsilva
# 10/03/2009

FILE="/export/scripts/uolzim/sbservers.txt"
YESTERDAY=`date -dyesterday +'%Y-%m-%d'`
YESTERDAYMAIL=`date -dyesterday +'%d/%m/%Y'`

for SRV in `awk {'print $1'} $FILE | grep -v ^#`
do SERVER=`echo $SRV | sed s,"\n",, | sed s,"\r",,`
   wget "http://zerfa1.adm.intranet/report/listhost?hostname=$SERVER" 1>/dev/null 2>&1
   if `grep "$YESTERDAYMAIL" listhost*$SERVER | grep itemok  1>/dev/null 2>&1`
   then 
      echo "$SERVER com backup" >> /tmp/msg_outputcom.txt
    else 
      echo "<br><a href="http://zerfa1.adm.intranet/report/listhost?hostname=$SERVER">$SERVER</a>" >> /tmp/msg_outputsem.txt
      grep "$SERVER " $FILE | awk -F"|" {'print $2'} >> /tmp/msg_outputsem.txt
   fi; 
   rm listhost*
done

echo "From: l-tec-sistemas-base@uolinc.com" > /tmp/msg_output.txt ;
echo "To: l-adm-portal-n1@uolinc.com" >> /tmp/msg_output.txt ;
echo "Subject: Backup UOLzim sem executar - $YESTERDAYMAIL" >> /tmp/msg_output.txt ;
echo "Content-type: text/html\; charset=iso-8859-1" >> /tmp/msg_output.txt ;
echo "Subject: Backup UOLzim sem executar - $YESTERDAYMAIL" >> /tmp/msg_output.txt ;
echo "Lista de servidores de Sistema Base sem backup no dia $YESTERDAYMAIL:" >> /tmp/msg_output.txt ;
echo >> /tmp/msg_output.txt ;
echo >> /tmp/msg_output.txt ;
cat /tmp/msg_outputsem.txt >> /tmp/msg_output.txt;

/usr/lib/sendmail -F admsys\@uol.com.br l-tec-sistemas-base\@uolinc.com < /tmp/msg_output.txt ;
/usr/lib/sendmail -F admsys\@uol.com.br l-adm-portal-n1\@uolinc.com < /tmp/msg_output.txt ;
/usr/lib/sendmail -F admsys\@uol.com.br wsilva\@uolinc.com < /tmp/msg_output.txt ;
rm -f /tmp/msg_output*.txt
